//
//  singleton.hpp
//  utilities
//
//  Created by Sam Jaffe on 4/28/13.
//  Copyright (c) 2013 Sam Jaffe. All rights reserved.
//

#pragma once

#include <memory>
#include <mutex>

template <class Impl>
class Singleton {
private:
    static std::unique_ptr<Impl> instance;
    static std::once_flag flag;
public:
    static Impl& getInstance() {
        std::call_once(flag, [](){instance.reset(new Impl());});
        return *instance;
    }
};

template <class Impl>
std::once_flag Singleton<Impl>::flag;

template <class Impl>
std::unique_ptr<Impl> Singleton<Impl>::instance;

